<template>
	<view class="content">
		<button class="size" @tap="createUpload">新建上传任务</button>
		<button class="size" @tap="clear">清除上传任务</button>
		<button class="size" @tap="pause">暂停上传任务</button>
		<button class="size" @tap="resume">恢复暂停的上传任务</button>
		<button class="size" @tap="abort">取消上传任务</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				watchId: null,
				task:null
			}
		},
		onLoad() {

		},
		methods: {
			createUpload() {
				let that = this;
				plus.gallery.pick(function(path) {
					console.log("path=>",path);
					that.task = plus.uploader.createUpload("https://jsonplaceholder.typicode.com/posts/", {
							method: "POST",
							priority: 100
						},
						function(t, status) {
							// 上传完成
							if (status == 200) {
								console.log("Upload success: " + t.url);
							} else {
								console.log("Upload failed: " + status);
							}
						}
					);
					that.task.addFile( path );
					that.task.start();
				}, function(e) {
					console.log("取消选择图片");
				}, {
					filter: "image"
				});
				
			},
			clear() {
				plus.uploader.clear();
			},
			pause() {
				this.task.pause();
			},
			resume() {
				this.task.resume();
			},
			abort() {
				this.task.abort()
			}

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
